﻿using System;
using System.Web;
using System.Web.Security;

namespace rpxlogindemo.handlers.login
{
    /// <summary>
    /// Summary description for LogoutHandler
    /// </summary>
    public class LogoutHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
        public LogoutHandler()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IHttpHandler Members

        bool IHttpHandler.IsReusable
        {
            get { return true; }
        }

        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            FormsAuthentication.SignOut();
            context.Session.Abandon();

            if (!string.IsNullOrEmpty(context.Request.Form["returnUrl"]))
                context.Response.Redirect(context.Server.UrlDecode(context.Request.QueryString["returnUrl"]));
            else
                context.Response.Redirect("~/");
        }

        #endregion
    }
}